package demo;

import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Predicate;

/**
 * 判断逻辑不太对等待完善
 *
 * @author dingwen
 * 2021.06.04 10:12
 */
public class OptionalConsumerTest {
    static String flag = "";

    public static void main(String[] args) {
        String test = "dding";

        // if  ding  1
        // else if ding 2
        // else if null 3
        // else if not null 4
        Predicate<Optional<String>> condition = opt -> opt.isPresent() && opt.get().equalsIgnoreCase("ding");
        Consumer<Optional<String>> consumer1 = OptionalConsumer.of((str) -> testIf(), OptionalConsumerTest::testElse,condition);
        Consumer<Optional<String>> consumer2 = OptionalConsumer.of((str) -> testElseIf1(), OptionalConsumerTest::testElseIf2);
        consumer1.andThen(consumer2).accept(Optional.of(test));
        System.out.println(flag);
    }

    public static void testIf() {
        flag = "1";
    }

    public static void testElse() {
        flag = "2";
    }

    public static void testElseIf1() {
        flag = "3";
    }

    public static void testElseIf2() {
        flag = "4";
    }
}
